#include <iostream>
#include <vector>
using namespace std;

void dfs(vector<vector<vector<int>>> &gh, vector<int> &dp, int &diameter, int u, int p)
{
	dp[u] = 0;
	for (auto e : gh[u]) {
		int v = e[0], w = e[1];
		if (v != p) {
			dfs(gh, dp, diameter, v, u);
			diameter = max(diameter, dp[u] + dp[v] + w);
			dp[u] = max(dp[u], dp[v] + w);
		}
	}
}

void dfs2(vector<vector<vector<int>>> &gh, vector<int> &dist, int u, int p)
{
	for (auto e : gh[u]) {
		int v = e[0], w = e[1];
		if (v != p) {
			dist[v] = dist[u] + w;
			dfs2(gh, dist, v, u);
		}
	}
}

int main()
{
	int n = 0;
	cin >> n;
	vector<vector<vector<int>>> gh(n + 1);
	vector<int> dp(n + 1, 0);
	int diameter = 0;
	for (int i = 0, u, v, w; i < n - 1; i++) {
		cin >> u >> v >> w;
		gh[u].push_back({ v, w });
		gh[v].push_back({ u, w });
	}

	//method1
	// dfs(gh, dp, diameter, 1, 0);
	// cout << diameter << endl;

	//method2
	vector<int> dist(n + 1, 0);
	dfs2(gh, dist, 1, 0);
	int mdist = INT32_MIN, u;
	for (int i = 1; i <= n; i++) {
		if (dist[i] > mdist) {
			mdist = dist[i];
			u = i;
		}
	}

	mdist = INT32_MIN;
        fill(dist.begin(), dist.end(), 0);
	dfs2(gh, dist, u, 0);
	for (int i = 1; i <= n; i++) {
		if (dist[i] > mdist) {
			mdist = dist[i];
			u = i;
		}
	}
	cout << mdist << endl;

	return 0;
}